'use strict';

CustomerModule.controller('MapController',
	function MapController($scope, $location, Map) {
		var map = Map.initMap();
		Map.locateMe();
		var marker = null;
		var circle = null;
		Map.addListener(map, 'click', function(event) {
			if(marker == null){
			   	marker = Map.addMarker(event.latLng,'Click to delete','common/img/store.png');
			   	Map.addListener(marker, 'click',function(event1){
			   		Map.removeFeature(marker);Map.removeFeature(circle);
			   		marker = null;
			   	});
			   	circle = Map.addCircle(map,event.latLng,750, true, '#ff0000');
			   	Map.addListener(circle, 'center_changed', function (event1){
			   		marker.setPosition(circle.getCenter());
			   		marker.setAnimation(google.maps.Animation.DROP);
			   	});
			}
			else{
				// When circle center is modified, the associated event is called, 
				// hence marker position is updated
				circle.setCenter(event.latLng);
			}
			
		});
});